import 'package:backend.core/core/domain/entities/google_play/google_play_one_time_purchased_item_info.dart';
import 'package:backend.core/core/domain/entities/google_play/google_play_purchased_item_acknowledgement_status.dart';
import 'package:backend.purchases/domain/entities/google_play_api/google_play_api_purchased_item.dart';

abstract class CreateGooglePlayOneTimePurchasedItemInfoFromApiOne {
  GooglePlayOneTimePurchasedItemInfo call({
    required GooglePlayApiOneTimePurchasedItem apiOneTimePurchasedItem,
    required String googlePlayUserId,
    required String purchaseToken,
    required String purchaseItemSku,
  });
}

class CreateGooglePlayOneTimePurchasedItemInfoFromApiOneImpl
    implements CreateGooglePlayOneTimePurchasedItemInfoFromApiOne {
  const CreateGooglePlayOneTimePurchasedItemInfoFromApiOneImpl();

  @override
  GooglePlayOneTimePurchasedItemInfo call({
    required GooglePlayApiOneTimePurchasedItem apiOneTimePurchasedItem,
    required String googlePlayUserId,
    required String purchaseToken,
    required String purchaseItemSku,
  }) {
    final GooglePlayPurchasedItemAcknowledgementStatus acknowledgementStatus;

    if (apiOneTimePurchasedItem.acknowledged) {
      acknowledgementStatus = GooglePlayPurchasedItemAcknowledgementStatus.acknowledged;
    } else {
      acknowledgementStatus = GooglePlayPurchasedItemAcknowledgementStatus.yetToBeAcknowledged;
    }

    return GooglePlayOneTimePurchasedItemInfo(
      purchaseItemSku: purchaseItemSku,
      purchaseToken: purchaseToken,
      googlePlayUserId: googlePlayUserId,
      test: apiOneTimePurchasedItem.test,
      acknowledgementStatus: acknowledgementStatus,
    );
  }
}
